package com.google.gwt.sample.contacts.shared.generated.types;

import java.io.Serializable;
import org.dmd.dmc.DmcInputStreamIF;
import org.dmd.dmc.DmcOutputStreamIF;
import org.dmd.dmc.DmcAttribute;
import org.dmd.dmc.DmcAttributeInfo;
import org.dmd.dmc.DmcValueException;
import com.google.gwt.sample.contacts.shared.generated.enums.*;

/**
 * This is the generated DmcAttribute derivative for values of type ContactTypeEnum
 * <P>
 * Generated from the contacts schema at version unknown
 * <P>
 * This code was auto-generated by the dmogenerator utility and shouldn't be alterred manually!
 * Generated from: org.dmd.dms.util.DmoTypeFormatter.dumpEnumType(DmoTypeFormatter.java:291)
 */
@SuppressWarnings("serial")
abstract public class DmcTypeContactTypeEnum extends DmcAttribute<ContactTypeEnum> implements Serializable {

    public DmcTypeContactTypeEnum(){
    }

    public DmcTypeContactTypeEnum(DmcAttributeInfo ai){
        super(ai);
    }

    protected ContactTypeEnum typeCheck(Object value) throws DmcValueException {
        ContactTypeEnum rc = null;

        if (value instanceof ContactTypeEnum){
            rc = (ContactTypeEnum)value;
        }
        else if (value instanceof String){
            rc = ContactTypeEnum.get((String)value);
        }
        else if (value instanceof Integer){
            rc = ContactTypeEnum.get((Integer)value);
        }
        else{
            throw(new DmcValueException("Object of class: " + value.getClass().getName() + " passed where object compatible with ContactTypeEnum expected."));
        }

        if (rc == null){
            throw(new DmcValueException("Value: " + value.toString() + " is not a valid ContactTypeEnum value."));
        }

        return(rc);
    }

    /**
     * Returns a clone of a value associated with this type.
     */
    public ContactTypeEnum cloneValue(ContactTypeEnum val){
        return(val);
    }

    /**
     * Writes a ContactTypeEnum.
     */
    public void serializeValue(DmcOutputStreamIF dos, ContactTypeEnum value) throws Exception {
        dos.writeShort(value.intValue());
    }

    /**
     * Reads a ContactTypeEnum.
     */
    public ContactTypeEnum deserializeValue(DmcInputStreamIF dis) throws Exception {
        return(ContactTypeEnum.get(dis.readShort()));
    }

}
